package com.suning.sawp.service.impl.dao.oga;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;

import com.suning.framework.dal.client.DalClient;
import com.suning.sawp.intf.dao.oga.ClerkCateGroupDaoService;
import com.suning.sawp.po.oga.ClerkCateGroup;

@Service
public class ClerkCateGroupDaoServiceImpl implements ClerkCateGroupDaoService {

    private static final Logger LOGGER = LoggerFactory.getLogger(ClerkCateGroupDaoServiceImpl.class);
    
    @Resource
    DalClient dalClient;

    /**
     * 功能描述: 数据入库方法<br>
     * 〈功能详细描述〉
     * 
     * @param cateGroup
     * @return 数据库主键ID
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @Override
    public boolean insertClerkCateGroup(ClerkCateGroup cateGroup) {
        try {
            dalClient.persist(cateGroup);
            return true;
        } catch (DuplicateKeyException e) {
            LOGGER.error("insertClerkCateGroup error.", e);
        }
        return false;
    }

    /**
     * 功能描述: 删除指定门店品类下的店员<br>
     * 〈功能详细描述〉
     * 
     * @param storeCode
     * @param cateCode
     * @param staffId
     * @return 删除条数
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @Override
    public int deleteClerkCateGroup(String storeCode, String cateCode, String staffId) {

        Map<String, Object> paramMap = new HashMap<String, Object>();
        if (StringUtils.isBlank(storeCode) || StringUtils.isBlank(cateCode) || StringUtils.isBlank(cateCode)) {
            return 0;
        }
        paramMap.put("storeCode", storeCode);
        paramMap.put("cateCode", cateCode);
        paramMap.put("staffId", staffId);

        return dalClient.execute("CLERK_CATE_GROUP.DELETE_CLERKCATEGROUP_BY_SCS", paramMap);
    }

    /**
     * 功能描述: 查询门店客户拓展品类列表<br>
     * 〈功能详细描述〉
     * 
     * @param storeCode
     * @return 品类集合
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @Override
    public List<Map<String, Object>> queryClerkCateGroup4Store(String storeCode) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        if (StringUtils.isBlank(storeCode)) {
            return null;
        }
        paramMap.put("storeCode", storeCode);

        return dalClient.queryForList("CLERK_CATE_GROUP.QUERY_CLERKCATEGROUP_4_STORE", paramMap);
    }

    /**
     * 功能描述: 品类人员汇总列表<br>
     * 〈功能详细描述〉
     * 
     * @param storeCode
     * @return 品类人员数集合
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @Override
    public List<Map<String, Object>> queryClerkCateGroup4StoreSize(String storeCode) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        if (StringUtils.isBlank(storeCode)) {
            return Collections.emptyList();
        }
        paramMap.put("storeCode", storeCode);

        return dalClient.queryForList("CLERK_CATE_GROUP.QUERY_CLERKCATEGROUP_4_STORE_SIZE", paramMap);
    }

    /**
     * 功能描述: <br>
     * 〈功能详细描述〉
     * 
     * @param storeCode
     * @param cateCode
     * @return 品类数集合
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @Override
    public List<Map<String, Object>> queryStaffWithCateCode(String storeCode, String cateCode) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        if (StringUtils.isBlank(storeCode) || StringUtils.isBlank(cateCode)) {
            return null;
        }
        paramMap.put("storeCode", storeCode);
        paramMap.put("cateCode", cateCode);

        return dalClient.queryForList("CLERK_CATE_GROUP.QUERY_STAFF_WITH_CATECODE", paramMap);
    }

}
